package com.lebang.common.util;

import com.lebangweb.common.DateUtil;

import java.util.Date;

/**
 * @author Eliohn on 2019/8/28.
 * @version 1.0
 */
public class ShowDateUtil {

    //返回两个日期相差多少 X天 X小时 X分钟 X秒
    public static String getDatePoor(Date endDate, Date nowDate) {

        long nd = 1000 * 24 * 60 * 60;
        long nh = 1000 * 60 * 60;
        long nm = 1000 * 60;
        long ns = 1000;
        // 获得两个时间的毫秒时间差异
        long diff = endDate.getTime() - nowDate.getTime();
        // 计算差多少天
        long day = diff / nd;
        // 计算差多少小时
        long hour = diff % nd / nh;
        // 计算差多少分钟
        long min = diff % nd % nh / nm;
        // 计算差多少秒//输出结果
        long sec = diff % nd % nh % nm / ns;
        return day + "天" + hour + "小时" + min + "分钟"+ sec+"秒";
    }

    public static String afterMinute(Date date, int minute){
        long time = minute * 60 * 1000;//30分钟
        Date afterDate = new Date(date.getTime() + time);//30分钟后的时间
        return  DateUtil.dateToString(afterDate, "yyyy-MM-dd HH:mm:ss");
    }
}
